﻿/********************************************************
 // Module Name    : Run Time Show Window
 // Purpose        : Application Action.
                	 Creates Action with MenuItem and treeview item
            		 The ActionCommand is translated for display
            		 If translated text contains &, the next character is the Mnemonic
 // Class Used     : GlobalVariable.cs, CommonFunctions.cs
 // Created By     : Harwinder 
 // Date           : 
**********************************************************/


using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using VAdvantage.Controls;
using VAdvantage.Utility;
using System.Text;

namespace VAdvantage.Apps
{
    /// <summary>
    /// Interface  
    /// </summary>
    public interface IActionName
    {
        string ActionName
        {
            get;
        }
    }

    public class AppsAction : IActionName
    {

        ///** Button Size     			*/
        ///public static final Dimension	BUTTON_SIZE = new Dimension(28,28);
        ///** Button Insets   			*/
        ////public static final Insets		BUTTON_INSETS = new Insets(0, 0, 0, 0);

        /* Default button Pading */
        //public static Padding BUTTON_PADDING = new Padding(2, 0, 3, 0);
        /* ToolStripButton */
        private ToolBarButton _button;
        //	MenuItem
        //private ToolStripMenuItem _menu;

        /*Command Name*/
        private String _action = null;
        /*ShortCut Key*/
        private Key _accelerator = Key.None;
        /*Pressed small image*/
        private ImageSource _smallPressed = null;
        /* Large ressed Image */
        private ImageSource _largePressed = null;
        /* small image */
        private ImageSource small = null;
        /* large Image */
        private ImageSource large = null;
        /*cretae button condition */
        private bool _toggle = false;
        /* is pressed */
        private bool _pressed = false;

        /* isEnabled */
        private bool _isEnabled = true;
         
        private string _text = "";
        /* dropdown items */
        //private ToolStripDropDownButton _dropDownButton = null;
        /* tool strip text */
        private string _toolTipText = "";
        /* event handler of item */
        public event RoutedEventHandler ActionPerformed;

        private ATreeViewItem _aTreeItem = null;

        //private AListBoxItem _aListBoxItem = null;

        private ImageText _aImageText = null;
        /// <summary>
        /// inteface function body 
        /// return Name of action
        /// </summary>
        public string ActionName
        {
            get { return _action; }
        }

        /// <summary>
        /// Application Action
        /// </summary>
        /// <param name="action"></param>
        /// <param name="accelerator"></param>
        /// <param name="toggle"></param>
        public AppsAction(String action, Key accelerator, bool toggle)
            : this(action, accelerator, null, toggle)
        {
        }

        public AppsAction(String action, String imageName, bool toolTip)
            
        {

        }

        /// <summary>
        ///   Application Action
        /// </summary>
        /// <param name="action"></param>
        /// <param name="accelerator"></param>
        /// <param name="text"></param>
        public AppsAction(String action, Key accelerator, String text)
            : this(action, accelerator, text, false)
        {
        }

        public AppsAction(String action, String imageName, String toolTipText)
            :this(action,imageName,toolTipText,true)
        {

        }
        public AppsAction(String action, String imageName , String toolTipText, bool toggle)
            :this(action,imageName,toolTipText,toggle,false)
        {
        }
        /// <summary>
        /// Application Action
        /// </summary>
        /// <param name="action"></param>
        /// <param name="accelerator"></param>
        /// <param name="toolTipText"></param>
        /// <param name="toggle"></param>
        public AppsAction(String action, String imageName , String toolTipText, bool toggle,bool isSmall)
        {

            _action = action;
            //_accelerator = accelerator;
            _toggle = toggle;
            _text = Msg.GetMsg(VAdvantage.Utility.Envs.GetContext(), action,true); //action;

            //	Data
            if (toolTipText == null)
                toolTipText =  Msg.GetMsg(VAdvantage.Utility.Envs.GetContext(), action);
            else
            {
                toolTipText = Msg.GetMsg(VAdvantage.Utility.Envs.GetContext(), toolTipText);
            }

            _toolTipText = toolTipText;
            int pos = toolTipText.IndexOf('&');
            if (pos != -1 && toolTipText.Length > pos)	//	We have a nemonic - creates ALT-_
            {
                char ch = toolTipText.ToUpper()[pos + 1];
                if (ch != ' ')
                {
                    toolTipText = toolTipText.Substring(0, pos) + toolTipText.Substring(pos + 1);
                    _toolTipText = toolTipText;
                }
            }

            // try getting the PNG icons first		
            // if PNG icons not found, try the GIF icons
            if (isSmall)
            {
                small = GetIcon(imageName, true);
            }
            else
            {
                large = GetIcon(imageName, false);
            }

            //    //  ToggleIcons have the pressed name with X
            if (_toggle)
            {
                if (isSmall)
                {
                    _smallPressed = GetIcon(imageName + "X", true);
                    if (_smallPressed == null)
                        _smallPressed = small;
                }
                else
                {
                    _largePressed = GetIcon(imageName + "X", false);
                    if (_largePressed == null)
                        _largePressed = large;
                }
            }

            ////    //	Attributes
            ////    putValue(Action.NAME, toolTipText);					//	Display
            ////    putValue(Action.SMALL_ICON, small);                 //  Icon
            ////    putValue(Action.SHORT_DESCRIPTION, toolTipText);	//	Tooltip
            ////    putValue(Action.ACTION_COMMAND_KEY, m_action);      //  ActionCammand
            ////    putValue(Action.ACCELERATOR_KEY, accelerator);      //  KeyStroke
            //////	putValue(Action.MNEMONIC_KEY, new Integer(0));      //  Mnemonic
            //////	putValue(Action.DEFAULT, text);						//	Not Used

            //    //	Create Button

            //if (_action == "ZoomAcross" || action == "Request")
            //{
            //    ////create dropdownmenuitem
            //    //_dropDownButton = new ToolStripDropDownButton();
            //    //_dropDownButton.Name = _action;
            //    //_dropDownButton.ImageAlign = ContentAlignment.MiddleCenter;
            //    //_dropDownButton.ImageScaling = ToolStripItemImageScaling.SizeToFit;
            //    //if (large != null)
            //    //{
            //    //    _dropDownButton.Image = large;
            //    //    _dropDownButton.Text = "";
            //    //}
            //    //_dropDownButton.ToolTipText = toolTipText;
            //    //_dropDownButton.DisplayStyle = ToolStripItemDisplayStyle.Image;
            //    //_dropDownButton.Click += new EventHandler(actionPerformed);
            //    //_dropDownButton.DropDownClosed += new EventHandler(_dropDownButton_DropDownClosed);
            //    //_dropDownButton.Margin = BUTTON_PADDING;
            //    // _dropDownButton.Enabled = false;
            //}
           // else
            //{

                //if (toggle)
                //{
                //    // m_button = new CToggleButton(this);
                //    //  m_button.setSelectedIcon(largePressed);
                //}
                //else
                //{
               

            //m_button.setSize(BUTTON_SIZE);
            //
           
        }

        public AppsAction(String action, Key accelerator, String toolTipText, bool toggle)
        {

            _action = action;
            _accelerator = accelerator;
            _toggle = toggle;

            //	Data
            if (toolTipText == null)
                toolTipText = Msg.GetMsg(VAdvantage.Utility.Envs.GetContext(), action);
            _text = toolTipText;
            int pos = toolTipText.IndexOf('&');
            if (pos != -1 && toolTipText.Length > pos)	//	We have a nemonic - creates ALT-_
            {
                char ch = toolTipText.ToUpper()[pos + 1];
                if (ch != ' ')
                {
                    toolTipText = toolTipText.Substring(0, pos) + toolTipText.Substring(pos + 1);
                    _toolTipText = toolTipText;
                }
            }

            // try getting the PNG icons first		
            // if PNG icons not found, try the GIF icons
            //  small = GetIcon(action, true);
            large = GetIcon(action, false);

            if (accelerator != Key.None)
            {
                ////StringFormat m = new StringFormat();
                //string key = accelerator.ToString();
                //if (key.Contains("',"))
                //{
                //    string[] str = key.Split(',');
                //    key = "";
                //    for (int i = str.Length - 1; i >= 0; i--)
                //    {
                //        if (i > 0)
                //        {
                //            key += str[i] + "+";
                //        }
                //        else
                //        {
                //            key += str[i];
                //        }
                //    }
                //}
                //toolTipText += " [" + key + "]";// ("#+#");
            }

            //    //  ToggleIcons have the pressed name with X
            if (_toggle)
            {
                //_smallPressed = GetIcon(action + "X", true);
                //if (_smallPressed == null)
                //    _smallPressed = small;

                _largePressed = GetIcon(action + "X", false);
                if (_largePressed == null)
                    _largePressed = large;
            }

            ////    //	Attributes
            ////    putValue(Action.NAME, toolTipText);					//	Display
            ////    putValue(Action.SMALL_ICON, small);                 //  Icon
            ////    putValue(Action.SHORT_DESCRIPTION, toolTipText);	//	Tooltip
            ////    putValue(Action.ACTION_COMMAND_KEY, m_action);      //  ActionCammand
            ////    putValue(Action.ACCELERATOR_KEY, accelerator);      //  KeyStroke
            //////	putValue(Action.MNEMONIC_KEY, new Integer(0));      //  Mnemonic
            //////	putValue(Action.DEFAULT, text);						//	Not Used

            //    //	Create Button

            if (_action == "ZoomAcross" || action == "Request")
            {
                ////create dropdownmenuitem
                //_dropDownButton = new ToolStripDropDownButton();
                //_dropDownButton.Name = _action;
                //_dropDownButton.ImageAlign = ContentAlignment.MiddleCenter;
                //_dropDownButton.ImageScaling = ToolStripItemImageScaling.SizeToFit;
                //if (large != null)
                //{
                //    _dropDownButton.Image = large;
                //    _dropDownButton.Text = "";
                //}
                //_dropDownButton.ToolTipText = toolTipText;
                //_dropDownButton.DisplayStyle = ToolStripItemDisplayStyle.Image;
                //_dropDownButton.Click += new EventHandler(actionPerformed);
                //_dropDownButton.DropDownClosed += new EventHandler(_dropDownButton_DropDownClosed);
                //_dropDownButton.Margin = BUTTON_PADDING;
                // _dropDownButton.Enabled = false;
            }
            else
            {

                //if (toggle)
                //{
                //    // m_button = new CToggleButton(this);
                //    //  m_button.setSelectedIcon(largePressed);
                //}
                //else
                //{
                _button = new ToolBarButton();
                // }
                _button.ActionName = action;
                //_button.ImageAlign = ContentAlignment.MiddleCenter;
                //_button.ImageScaling = ToolStripItemImageScaling.SizeToFit;
                //	Correcting Action items
                if (large != null)
                {
                    _button.Icon = large;
                    //_button.Text = "";
                }
                if (toolTipText != null && toolTipText.Length > 0)
                {
                    ToolTipService.SetToolTip(_button, toolTipText);
                }

                _button.Click += new RoutedEventHandler(actionPerformed);

                //_button.Margin = BUTTON_PADDING;
                //_button.Enabled = false;
            }
            //m_button.setSize(BUTTON_SIZE);
            //
            if (accelerator != null)
            {
                //        m_button.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(accelerator, action);
                //        m_button.getActionMap().put(action, this);
            }
        }
        /// <summary>
        /// clear DropDown
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void _dropDownButton_DropDownClosed(object sender, EventArgs e)
        {
            // clear dropdown of zoom button
            //_dropDownButton.HideDropDown();
            //_dropDownButton.DropDown = null;
        }



        /// <summary>
        ///  Get Icon with name action
        /// </summary>
        /// <param name="name"></param>
        /// <param name="small"></param>
        /// <returns></returns>
        private ImageSource GetIcon(String name, bool small)
        {
            String fullName ="Toolbar/"+ name + (small ? "16.png" : "22.png");
            ImageSource imgS  = VAdvantage.Utility.Envs.LoadImageSource(fullName);
            return imgS;
        }


        /// <summary>
        /// Get Name
        /// </summary>
        /// <returns></returns>
        public String GetName()
        {
            return _action;
        }

        /// <summary>
        /// </summary>
        /// <returns></returns>
        public ToolBarButton GetButton()
        {
            if (_button == null)
            {
                 _button = new ToolBarButton();
                 _button.Height = 32;
                // }
                _button.ActionName = _action;
                //_button.ImageAlign = ContentAlignment.MiddleCenter;
                //_button.ImageScaling = ToolStripItemImageScaling.SizeToFit;
                //	Correcting Action items
                if (large != null)
                {
                    _button.Icon = large;
                }
                _button.Text = _text;
                if (_toolTipText != null && _toolTipText.Length > 0)
                {
                  ToolTipService.SetToolTip(_button,_toolTipText);
                }

                //if(!action.Equals("Report", StringComparison.OrdinalIgnoreCase))
                    _button.Click += new RoutedEventHandler(actionPerformed);

                //_button.Margin = BUTTON_PADDING;
                //_button.Enabled = false;
            }

            return _button;


            }

        public ToolBarButton GetButton(string text)
        {
            if (_button == null)
            {
                _text = "";
                _button = new ToolBarButton();
                //_button.Height = 22;
                // }
                _button.ActionName = _action;
                //_button.ImageAlign = ContentAlignment.MiddleCenter;
                //_button.ImageScaling = ToolStripItemImageScaling.SizeToFit;
                //	Correcting Action items
                if (large != null)
                {
                    _button.Icon = large;
                }
                _button.Text = _text;
                if (_toolTipText != null && _toolTipText.Length > 0)
                {
                    ToolTipService.SetToolTip(_button, _toolTipText);
                }

                //if(!action.Equals("Report", StringComparison.OrdinalIgnoreCase))
                _button.Click += new RoutedEventHandler(actionPerformed);

                //_button.Margin = BUTTON_PADDING;
                //_button.Enabled = false;
            }

            return _button;


        }
       

        ///// <summary>
        ///// </summary>
        ///// <returns></returns>
        //public ToolStripDropDownButton GetDropDownButton()
        //{
        //    return _dropDownButton;
        //}


        /// <summary>
        /// Return MenuItem
        /// </summary>
        /// <returns></returns>
        public ATreeViewItem GetTreeViewItem()
        {
            if (_aTreeItem == null)
            {
                //if (_toggle)
                //{
                //    _aTreeItem = new ATreeViewItem();//  new CCheckBoxMenuItem(this);
                //    _aTreeItem.Margin = new Thickness(-17, 1, 0, 2);
                //    _aTreeItem.Icon = _smallPressed;
                //    _aTreeItem.Name = _action;

                    
                    
                //    //_menu.setSelectedIcon(m_smallPressed);
                //}
                //else
                {

                    _aTreeItem = new ATreeViewItem();//  new CCheckBoxMenuItem(this);
                    _aTreeItem.Margin = new Thickness(-17, 1, 0,2 );
                    _aTreeItem.Icon = small;
                    _aTreeItem.Name = _action;
                    
                }
                if (_accelerator != null)
                //{
                //    try
                //    {
                //        _menu.ShortcutKeys = _accelerator;
                //    }
                //    catch (Exception e)
                //    {
                //        Logging.VLogger.Get().Log(Logging.Level.SEVERE, "can-not create shortcutkeys for-" + _text, e);
                //    }
                //    _menu.ShowShortcutKeys = true;
                //}
                    _aTreeItem.Header  =  _text;
                _aTreeItem.ToolTipText = _toolTipText;
                //_menu.Enabled = false;
                _aTreeItem.MouseLeftButtonUp += (sender, e) =>
                    {
                       actionPerformed(_aTreeItem, EventArgs.Empty);
                    };
                        
            }
            return _aTreeItem;
        }


        public ImageText GetListBoxItem()
        {
            if (_aImageText == null)
            {
                if (_toggle)
                {
                    _aImageText = new ImageText();//  new CCheckBoxMenuItem(this);
                    _aImageText.Icon = _smallPressed;
                    _aImageText.Name = _action;



                    //_menu.setSelectedIcon(m_smallPressed);
                }
                else
                {

                    _aImageText = new ImageText();//  new CCheckBoxMenuItem(this);
                    _aImageText.Icon = small;
                    _aImageText.Name = _action;

                }
                if (_accelerator != null)
                    //{
                    //    try
                    //    {
                    //        _menu.ShortcutKeys = _accelerator;
                    //    }
                    //    catch (Exception e)
                    //    {
                    //        Logging.VLogger.Get().Log(Logging.Level.SEVERE, "can-not create shortcutkeys for-" + _text, e);
                    //    }
                    //    _menu.ShowShortcutKeys = true;
                    //}
                    _aImageText.Text = _text;
                _aImageText.ToolTipText = _toolTipText;
                //_menu.Enabled = false;
                _aImageText.MouseLeftButtonUp += (sender, e) =>
                {
                    actionPerformed(_aImageText, EventArgs.Empty);
                };

            }
            return _aImageText;
        }

        ///**
        // *	Set Delegate to receive the actionPerformed calls
        // *  @param al listener
        // */
        //public void SetDelegate(ActionListener al)
        //{
        //    m_delegate = al;
        //}	//	setDelegate

        /// <summary>
        /// Toggle
        /// </summary>
        /// <param name="pressed"></param>
        public void SetPressed(bool pressed)
        {
            if (!_toggle)
                return;
            _pressed = pressed;

            //	Set Button
            if (_button != null)
                _button.Icon = pressed ? _largePressed : large;//   .setSelected(pressed);

            if (_aTreeItem != null)
            {
                _aTreeItem.Icon = pressed ? _smallPressed : small;//   .setSelected(pressed);
            }

            if (_aImageText != null)
            {
                _aImageText.Icon = pressed ? _smallPressed : small;//   .setSelected(pressed);
            }


            //////	Set Menu
            //if (_menu != null)
            //    _menu.Image = pressed ? _smallPressed : small;
        }

        /// <summary>
        /// set enable
        /// </summary>
        /// <param name="enable"></param>
        public void SetEnabled(bool enable)
        {
            _isEnabled = enable;
            if (_button != null)
                _button.Enable = enable;//  .Image = pressed ? _largePressed : large;//   .setSelected(pressed);

            if (_aTreeItem != null)
                _aTreeItem.IsEnabled = enable;//  .Image = 

            if (_aImageText != null)
                _aImageText.IsEnabled = enable;//  .Image = 

            ////	Set Menu
            //if (_menu != null)
            //    _menu.Enabled = enable;//                 _menu.Image = pressed ? _smallPressed : small;
        }

        /// <summary>
        /// Is ToolStripMenuButton enabled
        /// </summary>
        /// <returns></returns>
        public bool IsEnabled()
        {
            return _isEnabled;
            //return _button.Enable;
        }

        /// <summary>
        /// IsPressed
        /// </summary>
        /// <returns></returns>
        public bool IsPressed()
        {
            return _pressed;
        }	//	isPressed

        ///**
        // * 	Get Mnemonic character
        // *	@return character
        // */
        //public Character getMnemonic()
        //{
        //    Object oo = getValue(Action.MNEMONIC_KEY);
        //    if (oo instanceof Integer)
        //        return (char)((Integer)oo).intValue();
        //    return null;
        //}	//	getMnemonic

        ///**
        // *	ActionListener
        // *  @param e Event
        // */
        private void actionPerformed(object sender, EventArgs e)
        {
           // Logging.VLogger.Get().Info("AppsAction.actionPerformed " + _text);
            //	Toggle Items
            if (_toggle)
                SetPressed(!_pressed);
            //	Inform
            if (ActionPerformed != null)
            {
                AppsEventArgs ee = new AppsEventArgs(_action);
                ActionPerformed((IActionName)this, ee);
            }
        }

        ///**
        // *	Dispose
        // */
        public void Dispose()
        {
            _button = null;
            _aTreeItem = null;
            _aImageText = null;
            //_menu = null;
        }

        /// <summary>
        /// String Info
        ///return String Representation
        /// </summary>
        /// <returns></returns>
        public override String ToString()
        {
            StringBuilder sb = new StringBuilder("AppsAction[");
            sb.Append(_action);
            //Object oo = getValue(Action.ACCELERATOR_KEY);
            //    if (oo != null)
            //        sb.append(",Accelerator=").append(oo);
            //    oo = getMnemonic();
            //    if (oo != null)
            //        sb.append(",MnemonicKey=").append(oo);
            sb.Append("]");
            return sb.ToString();
        }
    }

    /// <summary>
    /// Derived Class to add action name property in event args'ments
    /// </summary>
    public class AppsEventArgs : RoutedEventArgs
    {
        /* action Name */
        private string _action = "";

        /// <summary>
        /// Set Action Name
        /// </summary>
        /// <param name="name"></param>
        public AppsEventArgs(string name)
        {
            _action = name;
        }

        //Get acton Name
        public string GetActionCommand()
        {
            return _action;
        }
    }

    /// <summary>
    /// Derived class to show treeview item in window left and right expander 
    /// </summary>

    public class ATreeViewItem : TreeViewItem
    {
        //Image
        private Image _image = null;
        /* Item Text */
        private TextBlock txtHeader = null;
        /* image and text container */
        private StackPanel spItem = null;
        /* ttol tip text */
        private String _toolTipText = null;
        /* click handler */
        public event  RoutedEventHandler Click;

        /// <summary>
        /// std const
        /// Create new header (Image and Text)
        /// </summary>
        public ATreeViewItem()
        {
            spItem = new StackPanel() { Orientation = System.Windows.Controls.Orientation.Horizontal };
            _image = new Image() { Height = 18, Width = 18, HorizontalAlignment = System.Windows.HorizontalAlignment.Left, VerticalAlignment = System.Windows.VerticalAlignment.Center };
            _image.Visibility = Visibility.Collapsed;
            _image.Margin = new Thickness(1,1,5,1);

            txtHeader = new TextBlock() { VerticalAlignment = System.Windows.VerticalAlignment.Center, HorizontalAlignment = System.Windows.HorizontalAlignment.Left };



            txtHeader.Margin = new Thickness(1);
            spItem.Children.Add(_image);
            spItem.Children.Add(txtHeader);
            base.Header = spItem;
            this.Margin = new Thickness(-5, 0, 0, 0);
            //this.Foreground = new SolidColorBrush(Color.FromArgb(255, 59, 59, 59));
            //this.FontSize = 11;
            //this.FontWeight = FontWeights.Normal;

        }


        public new SolidColorBrush Foreground
        {
            set
            {
                this.txtHeader.Foreground = value;
            }
        }


        public new FontWeight FontWeight
        {
            set
            {
                this.txtHeader.FontWeight = value;
            }
        }

        public new double FontSize
        {
            set
            {
                this.txtHeader.FontSize = value;
            }
        }


        public ImageSource Icon
        {
            set
            {
                if (value != null)
                {
                    _image.Source = value;
                    _image.Visibility = System.Windows.Visibility.Visible;
                }
                else
                {
                    _image.Visibility = System.Windows.Visibility.Collapsed;
                }
            }
        }

        public new Object Header
        {
            set
            {
                if (value != null)
                    txtHeader.Text = value.ToString();
                else
                    txtHeader.Text = "";
            }
            get
            {
                return txtHeader.Text;
            }
        }

        public string ToolTipText
        {
            get
            {
                return _toolTipText;

            }

            set
            {
                _toolTipText = value;
                if (_toolTipText == null || _toolTipText.Length > 0)
                {

                    ToolTipService.SetToolTip(this, _toolTipText);
                }
            }
        }


        protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
        {
            base.OnMouseLeftButtonUp(e);
            if (Click != null)
            {
                Click(this, new RoutedEventArgs());
            }
        }
    }

    public class AListBoxItem : ListBoxItem
    {
        //Image
        private Image _image = null;
        /* Item Text */
        private TextBlock txtHeader = null;
        /* image and text container */
        private StackPanel spItem = null;
        /* ttol tip text */
        private String _toolTipText = null;
        /* click handler */
        public event EventHandler Click;

        /// <summary>
        /// std const
        /// Create new header (Image and Text)
        /// </summary>
        public AListBoxItem()
        {
            spItem = new StackPanel() { Orientation = System.Windows.Controls.Orientation.Horizontal };
            _image = new Image() { Height = 16, Width = 16, HorizontalAlignment = System.Windows.HorizontalAlignment.Left, VerticalAlignment = System.Windows.VerticalAlignment.Center };
            _image.Visibility = Visibility.Collapsed;
            _image.Margin = new Thickness(1, 1, 2, 1);
            txtHeader = new TextBlock() { VerticalAlignment = System.Windows.VerticalAlignment.Center, HorizontalAlignment = System.Windows.HorizontalAlignment.Left };

            txtHeader.Margin = new Thickness(1, 1, 1, 1);
            spItem.Children.Add(_image);
            spItem.Children.Add(txtHeader);
            base.Content = spItem;
           // this.Margin = new Thickness(-5, 0, 0, 0);
            //this.Foreground = new SolidColorBrush(Color.FromArgb(255, 59, 59, 59));
            //this.FontSize = 11;
            //this.FontWeight = FontWeights.Normal;

        }
        
        public new SolidColorBrush Foreground
        {
            set
            {
                this.txtHeader.Foreground = value;
            }
        }

        public new FontWeight FontWeight
        {
            set
            {
                this.txtHeader.FontWeight = value;
            }
        }

        public new double FontSize
        {
            set
            {
                this.txtHeader.FontSize = value;
            }
        }

        public ImageSource Icon
        {
            set
            {
                if (value != null)
                {
                    _image.Source = value;
                    _image.Visibility = System.Windows.Visibility.Visible;
                }
                else
                {
                    _image.Visibility = System.Windows.Visibility.Collapsed;
                }
            }
        }

        public new Object Header
        {
            set
            {
                if (value != null)
                    txtHeader.Text = value.ToString();
                else
                    txtHeader.Text = "";
            }
            get
            {
                return txtHeader.Text;
            }
        }

        public string ToolTipText
        {
            get
            {
                return _toolTipText;

            }

            set
            {
                _toolTipText = value;
                if (_toolTipText == null || _toolTipText.Length > 0)
                {

                    ToolTipService.SetToolTip(this, _toolTipText);
                }
            }
        }

        protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
        {
            base.OnMouseLeftButtonUp(e);
            if (Click != null)
            {
                Click(this, EventArgs.Empty);
            }
        }
    }
}
